<template>
    <!-- 企业主要管理人信息 -->
    <div class="e-table">
        <div class="top">
            <div class="left">
                <div>
                    <el-button
                        size="small"
                        type="primary"
                        plain
                        @click="aptitudeClickAdd"
                        >添加</el-button
                    >
                    <el-button
                        size="small"
                        type="primary"
                        plain
                        @click="handleBatchDownload"
                        v-if="isBatch"
                        >批量下载</el-button
                    >
                    <el-button
                        size="small"
                        type="primary"
                        plain
                        @click="handleBatchDelete"
                        v-if="isBatch"
                        >批量删除</el-button
                    >
                </div>
                <div class="batchBox" @click="batchOperation">
                    <img class="batchicon" src="@/assets/piliang.png" />
                    <span class="batchfont">{{ batch }}</span>
                </div>
            </div>
            <div class="right" v-if="!isTableRowClass">
                <div class="squarecolor">
                    <div class="color colorAdd"></div>
                    <span>新增</span>
                </div>
                <div class="squarecolor item">
                    <div class="color colorUpdate"></div>
                    <span>修改</span>
                </div>
                <div class="squarecolor">
                    <div class="color colorDel"></div>
                    <span>删除/过期</span>
                </div>
            </div>
        </div>
        <div
            style="margin-bottom: 20px"
            class="errorMsg"
            v-if="errorMsg.length > 0"
        >
            <span
                style="display: block"
                v-for="(item, index) in errorMsg"
                :key="index"
            >
                {{ item }}
            </span>
        </div>
        <el-table
            :data="aptitudeTable"
            border
            style="width: 100%"
            class="table"
            :max-height="$store.state.tableHeight"
            @selection-change="handleDetailSelectionChange"
            @cell-click="cellClick"
            :row-class-name="tableRowClass"
            ref="table"
            v-sortTable="{
                tableData: aptitudeTable,
                _this: this,
                ref: 'table'
            }"
        >
            <el-table-column
                type="selection"
                width="55"
                v-if="isBatch"
            ></el-table-column>
            <el-table-column label="序号" type="index" width="60">
            </el-table-column>
            <el-table-column fixed label="操作" width="120">
                <template slot-scope="{ row, $index }">
                    <div class="handle">
                        <el-upload
                            style="margin: 7px 5px 0px 0px"
                            class="upload-demo"
                            :action="uploadUrl"
                            :data="{
                                bucketName,
                                relationId,
                                orgCode
                            }"
                            :before-upload="beforeAvatarUpload"
                            :accept="accept"
                            :on-success="attachOnSuccess"
                            :http-request="uploadBefore"
                            :show-file-list="false"
                            name="files"
                        >
                            <img src="@/assets/btn/commit.png" />
                        </el-upload>
                        <img
                            v-if="row.id"
                            src="@/assets/btn/downLoad.png"
                            @click="handleDownload(row)"
                            style="margin-right: 5px"
                        />
                        <img
                            v-if="row.changeType != -1"
                            src="@/assets/btn/delete.png"
                            @click="handleDelete(row, $index)"
                        />
                        <img
                            v-else
                            src="@/assets/btn/cancelDelete.png"
                            @click="revoke($index)"
                        />
                        <img
                            style="margin-left: 10px"
                            src="@/assets/btn/preview.png"
                            @click="preview($index)"
                        />
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="人员类别" width="200">
                <template slot-scope="{ row, $index }">
                    <el-select
                        v-model="row.personTypeValue"
                        @change="
                            getPersonType(row, row.personTypeValue, $index)
                        "
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in personType"
                            :key="item.kvId"
                            :label="item.kvKey"
                            :value="item.kvValue"
                        >
                        </el-option>
                    </el-select>
                </template>
            </el-table-column>
            <el-table-column prop="staffName" label="姓名" width="120">
                <template slot-scope="{ row }">
                    <el-input
                        @change="modifyState(row)"
                        v-model.trim="row.staffName"
                    ></el-input>
                </template>
            </el-table-column>
            <el-table-column
                label="身份证号码"
                min-width="190"
                show-overflow-tooltip
            >
                <template slot-scope="{ row }">
                    <el-input
                        @change="modifyState(row)"
                        maxlength="18"
                        v-model.trim="row.idCard"
                    ></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="tel" label="联系电话" width="140">
                <template slot-scope="{ row }">
                    <el-input
                        @change="modifyState(row)"
                        maxlength="11"
                        v-model.trim="row.tel"
                    ></el-input>
                </template>
            </el-table-column>
            <el-table-column label="证书及编号" width="190">
                <template slot-scope="{ row }">
                    <el-input
                        @change="modifyState(row)"
                        v-model.trim="row.certNo"
                    ></el-input>
                </template>
            </el-table-column>
            <el-table-column label="资格证书有效开始时间" width="150">
                <template slot-scope="{ row }">
                    <el-date-picker
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        v-model="row.beginDate"
                        style="width: 100%"
                        @change="modifyState(row)"
                    ></el-date-picker>
                </template>
            </el-table-column>
            <el-table-column label="资格证书有效结束时间" width="150">
                <template slot-scope="{ row }">
                    <el-date-picker
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        v-model="row.endDate"
                        style="width: 100%"
                        @change="modifyState(row)"
                    ></el-date-picker>
                </template>
            </el-table-column>
            <el-table-column prop="fileName" label="身份证附件" min-width="150">
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import ossRequest from '@/api/oss/oss.js'
import { bytesToSize, showLoading, hideLoading, getUuid } from '@/utils/common'
import { staffList } from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractor.js'
import subcontractorChange from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractorChange.js'
//import ComPagination from '@/components/pagination/pagination'
import call from '@/api/OutsourcingartyAdmin/getAllType.js'
import service from '@/utils/request'
export default {
    props: {
        bucketName: {
            type: String,
            default: '',
            require: true
        },
        billId: {
            type: String,
            default: '',
            require: true
        },
        outerNames: {
            type: String,
            default: '',
            require: true
        },
        // 父组件传过来的数据
        firmAdminTables: {
            type: Array,
            require: true
        },
        fun: {
            type: Function,
            default: null
        },
        // 是否需要修改样式
        isTableRowClass: {
            type: Boolean,
            default: false
        },
        // 分包商类型
        subcontractorTypeValue: {
            type: Array,
            default: () => {
                return []
            }
        },
        // 是否为境外单位
        isAbroadUnit: {
            type: [String, Number],
            default: ''
        },
        // 是否通过验证
        firmAdminSend: {
            type: Boolean,
            default: false
        }
    },
    data () {
        return {
            isBatch: false, //是否进入批量操作
            batch: '进入批量管理',
            checkedDetail: [], //选中的数据
            //上传的地址
            uploadUrl: '/oss/uploader',
            accept: '.jpg,jpeg,.png,.pdf',
            relationId: '',
            pagination: {
                limit: 10, //	每页显示条数
                name: '', //合同名称
                orgName: '', //机构
                page: 1 //当前页数
            },
            totalPage: 0, //总页数
            rowIndex: '',
            personType: [], //人员类型
            errorMsg: [], //验证数组
            isFrequency: true, //控制初始化数据方法只会执行一次
            aptitudeTable: [], //表单数据
            deleteDate: {}, //删除对象
            oldDate: [] //列表查回来的基础数据
        }
    },
    async created () {
        call.getCredential('人员类型').then(res => {
            this.personType = res
            if (this.isFrequency) {
                this.isFrequency = false
            }
        })
        // 初始化主要管理列表
        this.staffList(this.billId)
    },
    // 询问产品。切换的逻辑，再做判断
    computed: {
        orgCode () {
            return this.$store.state.userInfo.orgInfo.shortCode
        },
        //表格数据
        watchAptitudeTable () {
            return JSON.parse(JSON.stringify(this.aptitudeTable))
        }
    },
    methods: {
        mountWatch () {
            this.unWatch = this.$watch(
                'watchAptitudeTable',
                function (newData, oldData) {
                    if (oldData)
                        oldData.forEach((item, index) => {
                            if (newData[index]) {
                                if (
                                    JSON.stringify(item) !==
                                        JSON.stringify(newData[index]) &&
                                    item.id
                                ) {
                                    this.$set(
                                        this.aptitudeTable[index],
                                        'changeType',
                                        2
                                    )
                                    this.$set(
                                        this.aptitudeTable[index],
                                        'state',
                                        2
                                    )
                                }
                                if (
                                    newData[index].state == -1 ||
                                    item.state == -1
                                ) {
                                    this.$set(
                                        this.aptitudeTable[index],
                                        'changeType',
                                        -1
                                    )
                                    this.$set(
                                        this.aptitudeTable[index],
                                        'state',
                                        -1
                                    )
                                }
                            }
                        })
                },
                { deep: true }
            )
        },
        //修改行样式
        tableRowClass ({ row }) {
            if (this.isTableRowClass) {
                return
            } else {
                if (row.state == -1) {
                    return 'red'
                } else if (row.state == 1) {
                    return 'green'
                } else if (row.state == 2) {
                    return 'yellow'
                }
                return ''
            }
        },
        //选择人员类型的事件
        // eslint-disable-next-line no-unused-vars
        getPersonType (row, personTypeValue, $index) {
            this.modifyState(row)
            const obj = this.personType.find(
                item => item.kvValue === personTypeValue
            )
            this.$set(this.aptitudeTable[$index], 'personTypeKey', obj.kvKey)
        },
        //是否批量管理
        batchOperation () {
            this.isBatch = !this.isBatch
            if (this.isBatch) {
                this.batch = '退出批量管理'
                this.$refs.table.clearSelection()
            } else {
                this.batch = '进入批量管理'
            }
        },
        cellClick (row) {
            //是第几行
            this.rowIndex = this.aptitudeTable.findIndex(x => x === row)
        },
        //初始化添加11行
        aptitudeAddRow () {
            // 初始化人员类型名字

            let personTypeKeys = [
                '董事会成员（持股人）',
                '董事会成员（持股人）',
                '董事会成员（持股人）',
                '法人代表',
                '实际控制人',
                '总经理',
                '总工程师',
                '技术负责人',
                '质量负责人',
                '安全负责人',
                '班组长'
            ]
            let personTypeValues = [
                '0',
                '0',
                '0',
                '1',
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8'
            ]
            // 判断数据是否完整并且符合条件
            /**
             * 1.分包商类型选择“劳务合作、施工分包”中的1个或2个，且不是境外单位的时候
             * 1)董事会成员（持股人）默认生成3行，至少填写1行
             * 2)法人代表、实际控制人、总经理、总工程师、技术质量负责人、质量负责人、安全负责人和班组长默认生成1行，至少填写1行；
             * 2.勾选了境外单位或外包方类型只有其它的时候，则默认生成1行“法人代表”且必填
             */
            if (
                (this.subcontractorTypeValue.includes('8') ||
                    this.subcontractorTypeValue.includes('9')) &&
                this.isAbroadUnit == 0
            ) {
                for (var i in personTypeKeys) {
                    let obj = {
                        beginDate: '',
                        certNo: '',
                        changeType: 1,
                        email: '',
                        endDate: '',
                        fileName: '',
                        gmtCreate: '',
                        gmtModified: '',
                        id: '',
                        idCard: '',
                        outerBillId: this.billId,
                        outerName: this.outerNames, //外包方名字,,
                        outerTypeKey: '',
                        outerTypeValue: '',
                        personTypeKey: personTypeKeys[i], //人员类型【name】
                        personTypeValue: personTypeValues[i], //人员类型【id】
                        relationId: '',
                        sourceId: '',
                        staffName: '',
                        state: 1,
                        tel: '',
                        uuid: getUuid(), //本地的uuid区分每条数据
                        newState: '1', //当期新增字段，判断是当前次新增的数据还是从后端请求回来的数据
                        dialogImage: '', //图片预览
                        filePath: '' //上传路径
                    }
                    this.aptitudeTable.push(obj)
                }
            } else {
                let obj = {
                    beginDate: '',
                    certNo: '',
                    changeType: 1,
                    email: '',
                    endDate: '',
                    fileName: '',
                    gmtCreate: '',
                    gmtModified: '',
                    id: '',
                    idCard: '',
                    outerBillId: this.billId,
                    outerName: this.outerNames, //外包方名字,,
                    outerTypeKey: '',
                    outerTypeValue: '',
                    personTypeKey: '法人代表', //人员类型【name】
                    personTypeValue: '1', //人员类型【id】
                    relationId: '',
                    sourceId: '',
                    staffName: '',
                    state: 1,
                    tel: '',
                    uuid: getUuid(), //本地的uuid区分每条数据
                    newState: '1', //当期新增字段，判断是当前次新增的数据还是从后端请求回来的数据
                    dialogImage: '', //图片预览
                    filePath: '' //上传路径
                }
                this.aptitudeTable.push(obj)
            }
            this.isLocalDel = true
        },
        // 点击添加一行
        aptitudeClickAdd () {
            let obj = {
                beginDate: '',
                certNo: '',
                changeType: 1,
                email: '',
                endDate: '',
                fileName: '',
                gmtCreate: '',
                gmtModified: '',
                id: '',
                idCard: '',
                outerBillId: this.billId,
                outerName: this.outerNames,
                outerTypeKey: '',
                outerTypeValue: '',
                personTypeKey: '', //人员类型【name】
                personTypeValue: '', //人员类型【id】
                relationId: '',
                sourceId: '',
                staffName: '',
                state: 1,
                tel: '',
                uuid: getUuid(), //本地的uuid区分每条数据
                newState: '1', //当期新增字段，判断是当前次新增的数据还是从后端请求回来的数据
                dialogImage: '', //图片预览
                filePath: '' //上传路径
            }
            this.aptitudeTable.push(obj)
        },
        //选中的行
        handleDetailSelectionChange (selection) {
            this.checkedDetail = selection
        },
        //删除一行
        handleDelete (row, $index) {
            if (this.isTableRowClass) {
                this.clientPop(
                    'info',
                    this.oneDeleteErr,
                    this.callback(row, $index)
                )
            } else {
                this.clientPop(
                    'info',
                    this.oneDeleteErr,
                    this.callbacks(row, $index)
                )
            }
        },
        // 编辑删除回调
        callback (row, index) {
            return () => {
                if (row.id) {
                    let data = []
                    row.changeType = -1
                    // 判断是否是原单数据，【只有变更数据才会有原单id】
                    if (row.sourceId) {
                        row.state = -1
                    }
                    data.push(row)
                    this.$emit('getFirmAdminData', data)
                } else {
                    this.aptitudeTable.splice(index, 1)
                }
            }
        },
        // 变更删除回调
        callbacks (row, index) {
            return () => {
                if (!row.newState) {
                    this.aptitudeTable[index].changeType = -1
                    this.aptitudeTable[index].state = -1
                } else {
                    this.aptitudeTable.splice(index, 1)
                }
            }
        },
        // 撤销
        revoke (index) {
            this.aptitudeTable[index].changeType = 0
            this.aptitudeTable[index].state = 1
        },
        //批量删除
        handleBatchDelete () {
            const length = this.checkedDetail.length
            this.clientPop(
                'info',
                `已选择【${length}】条数据，确定要删除吗？`,
                this.delete
            )
        },
        delete () {
            this.checkedDetail.filter(item => {
                // 如果有id ，则改changeType为-1
                if (item.id) {
                    item.changeType = -1
                } else {
                    // 如果没有id，判断uuid是否相同，相同则在原数据删除
                    this.aptitudeTable.map((items, index) => {
                        if (item.uuid == items.uuid) {
                            this.aptitudeTable.splice(index, 1)
                        }
                    })
                }
            })
            // 直接过滤所有无id的数据
            let data = this.checkedDetail.filter(item => {
                if (item.id) {
                    return item
                }
            })
            this.$emit('getFirmAdminData', data)
        },
        //下载某一行
        async handleDownload (obj) {
            showLoading()
            const url = obj.dialogImage
            const fileNameFull = obj.fileName
            const fileExt = fileNameFull.split('.').pop()
            if (
                ['jpg', 'jpeg', 'gif', 'png', 'bmp'].indexOf(
                    fileExt.toLowerCase()
                ) === -1
            ) {
                const { httpGetFile } = service
                const data = await httpGetFile({ url })
                const blob = new Blob([data])
                const reader = new FileReader()
                reader.readAsDataURL(blob)
                reader.onload = function (e) {
                    this.autoClick({
                        fileName: fileNameFull,
                        url: e.target.result
                    })
                }.bind(this)
            } else {
                this.downloadIamge(url, fileNameFull)
            }
            hideLoading()
        },
        downloadIamge (imgsrc, fileName) {
            //下载图片地址和图片名
            var image = new Image()
            // 解决跨域 Canvas 污染问题
            image.setAttribute('crossOrigin', 'anonymous')
            image.onload = function () {
                const canvas = document.createElement('canvas')
                canvas.width = image.width
                canvas.height = image.height
                const context = canvas.getContext('2d')
                context.drawImage(image, 0, 0, image.width, image.height)
                const _dataURL = canvas.toDataURL('image/png') //得到图片的base64编码数据

                const blob_ = this.dataURLtoBlob(_dataURL) // 用到Blob是因为图片文件过大时，在一部风浏览器上会下载失败，而Blob就不会

                const url = {
                    name: fileName || '图片.png', // 图片名称不需要加.png后缀名
                    src: blob_
                }

                if (window.navigator.msSaveOrOpenBlob) {
                    // if browser is IE
                    navigator.msSaveBlob(url.src, url.name) //filename文件名包括扩展名，下载路径为浏览器默认路径
                } else {
                    this.autoClick({
                        fileName: url.name,
                        url: window.URL.createObjectURL(url.src)
                    })
                }
            }.bind(this)
            image.src = imgsrc
        },
        dataURLtoBlob (dataurl) {
            var arr = dataurl.split(','),
                mime = arr[0].match(/:(.*?);/)[1],
                bstr = window.atob(arr[1]),
                n = bstr.length,
                u8arr = new Uint8Array(n)
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n)
            }
            return new Blob([u8arr], { type: mime })
        },
        autoClick ({ fileName, url }) {
            const elink = document.createElement('a')
            elink.download = fileName
            elink.style.display = 'none'
            elink.href = url
            document.body.appendChild(elink)
            elink.click()
            document.body.removeChild(elink)
        },
        //批量下载
        handleBatchDownload () {},
        //文件大小
        beforeAvatarUpload (file) {
            const isLt2M = file.size / 1024 / 1024 < 20

            if (!isLt2M) {
                this.clientPop('err', '上传文件大小不能超过 20MB！')
            }
            return isLt2M
        },
        //上传成功
        attachOnSuccess () {
            this.getObjectByRelationId()
        },
        //获取上传成功的对象
        getObjectByRelationId () {
            if (!this.relationId) return
            return ossRequest
                .getObjectByRelationId({ relationId: this.relationId })
                .then(res => {
                    res.map(x => {
                        x.fileName = x.objectName
                        return scrollX
                    })
                    this.$set(
                        this.aptitudeTable[this.rowIndex],
                        'dialogImage',
                        res[0].objectPath
                    )
                    this.$set(
                        this.aptitudeTable[this.rowIndex],
                        'fileName',
                        res[0].objectName
                    )
                    this.$set(
                        this.aptitudeTable[this.rowIndex],
                        'relationId',
                        this.relationId
                    )
                    this.modifyState(this.aptitudeTable[this.rowIndex])
                })
        },
        bytesToSize (byte) {
            return bytesToSize(byte)
        },
        //覆盖默认的上传行为，可以自定义上传的实现
        uploadBefore (params) {
            this.$Ajax
                .httpGet({
                    url: '/uid/builder?num=1',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(res => {
                    params.data.relationId = res[0]
                    this.relationId = res[0]
                    let obj = {
                        ...params.data,
                        files: params.file
                    }
                    this.$Ajax
                        .httpPostForm({
                            url: this.uploadUrl,
                            params: obj
                        })
                        .then(() => {
                            this.attachOnSuccess()
                        })
                })
                .catch(error => {
                    this.clientPop('err', error, this.handleClose)
                })
        },
        //新增数据
        newData () {
            this.aptitudeTable.find(item => {
                item.outerBillId = this.billId
            })
            this.$Ajax
                .httpPost({
                    url: '/outer/subcontractor/change/staff/create',
                    params: this.aptitudeTable
                })
                .then(() => {
                    this.fun()
                })
        },
        //保存
        preserve () {
            this.errorMsg = []
            let isStr = false
            // 首先将changeTy为-1的过滤掉
            let data = this.aptitudeTable.filter(item => {
                return item.changeType != -1
            })
            data.forEach((item, index) => {
                let str1 = `请上传第 ${index + 1} 行的`
                if (item.fileName === '' || item.fileName === null) {
                    let str = '身份证附件,'
                    isStr = true
                    str1 += str
                }

                if (item.beginDate === '' || item.beginDate === null) {
                    let str = '资格证书有效开始时间 ,'
                    isStr = true
                    str1 += str
                }
                if (item.endDate === '' || item.endDate === null) {
                    let str = '资格证书有效结束时间,'
                    isStr = true
                    str1 += str
                }

                if (item.staffName === '' || item.staffName === null) {
                    let str = '姓名,'
                    isStr = true
                    str1 += str
                }
                if (
                    item.personTypeValue === '' ||
                    item.personTypeValue === null
                ) {
                    let str = '人员类别,'
                    isStr = true
                    str1 += str
                }
                if (Date.parse(item.beginDate) >= Date.parse(item.endDate)) {
                    let str = '结束时间必须大于开始时间,'
                    isStr = true
                    str1 += str
                }
                if (item.tel === '' || item.tel === null) {
                    let str = '联系电话,'
                    isStr = true
                    str1 += str
                } else {
                    if (!/^1[3-9]\d{9}$/.test(item.tel)) {
                        let str = '联系电话格式不正确！'
                        isStr = true
                        str1 += str
                    }
                }
                if (item.idCard === '' || item.idCard === null) {
                    let str = '身份证号码,'
                    isStr = true
                    str1 += str
                } else {
                    if (
                        !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(
                            item.idCard
                        )
                    ) {
                        let str = '身份证号码格式不正确！'
                        isStr = true
                        str1 += str
                    }
                }
                if (item.certNo === '' || item.certNo === null) {
                    let str = '证书及编号,'
                    isStr = true
                    str1 += str
                }
                if (isStr) {
                    this.errorMsg.push(str1)
                }
            })
            if (this.errorMsg.length > 0) {
                this.$emit('update:firmAdminSend', false)
                this.$emit('setError', 'firmAdmin')
                return
            } else {
                if (data.length > 0) {
                    // 调用新增方法
                    this.staffAdd(data)
                } else {
                    this.$emit('update:firmAdminSend', false)
                    this.$emit('setError', 'firmAdmin')
                    this.errorMsg.push('请至少包含一条数据')
                }
            }
        },
        // 列表
        async staffList (val) {
            // 如果有isTableRowClass，则调编辑页面的资质接口，否则调变更页面的资质接口
            if (this.isTableRowClass) {
                let data = await staffList(val)
                if (data.length > 0) {
                    this.aptitudeTable = data
                } else {
                    // 如果没有数据再初始化基础数据
                    this.aptitudeAddRow() //初始化数据
                }
            } else {
                let data = await subcontractorChange.findByIdstaff(val)
                if (data.length > 0) {
                    this.aptitudeTable = data
                    this.oldDate = JSON.parse(
                        JSON.stringify(this.aptitudeTable)
                    )
                } else {
                    // 如果没有数据再初始化基础数据
                    this.aptitudeAddRow() //初始化数据
                }
            }
        },
        // 修改样式
        modifyState (row) {
            this.oldDate.map(item => {
                if (item.id == row.id && row.relationId) {
                    // if( !this.isObjectValueEqual(item, row)) {
                    this.aptitudeTable.map(items => {
                        if (items.id == row.id) {
                            return (items.state = 2)
                        }
                    })
                    // }
                }
            })
        },
        // 新增
        async staffAdd (val) {
            let oldArry = this.personType.map(item => {
                return item.kvKey
            })
            /**
             * 1)董事会成员（持股人）默认生成3行，至少填写1行
             * 2)法人代表、实际控制人、总经理、总工程师、技术质量负责人、质量负责人、安全负责人和班组长默认生成1行，至少填写1行；
             */
            if (
                (this.subcontractorTypeValue.includes('8') ||
                    this.subcontractorTypeValue.includes('9')) &&
                this.isAbroadUnit == 0
            ) {
                let isContain = [] //定义人员类型临时数组
                // 将人员类型存入临时数组
                isContain = val.map(item => {
                    if (item.state != -1) {
                        return item.personTypeKey
                    }
                })
                // 去重
                let isContains = [...new Set(isContain)]
                // 检验哪些不包含在该数组
                let newData = oldArry.filter(item => {
                    if (!isContains.includes(item)) {
                        return item
                    }
                })
                //判断人员类型是否包含9种类型，不包含则提示
                if (newData.length < 1) {
                    // 调用接口
                    val.map(item => {
                        if (item.id) {
                            item.changeType = 2
                            return item
                        }
                    })
                    this.$emit('update:firmAdminSend', true)
                    this.$emit('update:firmAdminTables', val)
                } else {
                    this.$emit('update:firmAdminSend', false)
                    this.$emit('setError', 'firmAdmin')
                    this.errorMsg.push(`${newData.splice(',')}` + '未填写')
                }
            } else {
                let isContain = [] //定义人员类型临时数组
                // 将人员类型存入临时数组
                isContain = val.map(item => {
                    if (item.state != -1) {
                        return item.personTypeKey
                    }
                })
                //判断证书类型是否包含法人代表，不包含则提示
                if (isContain.includes('法人代表')) {
                    this.$emit('update:firmAdminSend', true)
                    this.$emit('update:firmAdminTables', val)
                } else {
                    this.$emit('update:firmAdminSend', false)
                    this.$emit('setError', 'firmAdmin')
                    this.errorMsg.push('人员类型必须包含:法人代表')
                }
            }
        },
        //预览附件
        preview (val) {
            if (this.aptitudeTable[val].dialogImage) {
                window.open(this.aptitudeTable[val].dialogImage)
            } else {
                this.clientPop('err', '请先上传附件')
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.handle {
    display: flex;
    align-items: center;
    text-align: left;
    div {
        cursor: pointer;
    }
    .download {
        font-size: 23px;
        font-weight: bold;
        color: rgb(122, 168, 24);
    }
}
</style>
